package com.szr.leex.po.test;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import com.szr.leex.po.BaseEntity;
import com.szr.leex.po.converter.GenderConverter;
import com.szr.leex.po.enums.GenderEnum;
import com.szr.leex.po.enums.WeekEnum;

import lombok.Data;

/**
 * student
 * Created by WangChen on 2018/8/29 17:24.
 */
@Entity
@Table(name = "student")
@Data
public class Student extends BaseEntity {
    @Column(length = 64)
    private String name; // student name
    private int age; // student age

    // 关于Enum，详见jdk源码java.lang.Enum

    // alter table student add column gender char(1)
    // char(1) 是由于GenderType使用的sqlTypeDescriptor是CharTypeDescriptor.INSTANCE，
    // 具体参见com.szr.leex.dao.converter.GenderType的源码
    @Type( type = "com.szr.leex.dao.converter.GenderType" )
    private GenderEnum gender = GenderEnum.FEMALE; // gender

    // alter table student add column gender2 varchar(255)
    // stored according to the enum value’s name, as indicated by java.lang.Enum#name
    @Enumerated(EnumType.STRING)
    private GenderEnum gender2 = GenderEnum.FEMALE; // gender

    // alter table student add column gender3 integer
    // stored according to the enum value’s ordinal position within the enum class, as indicated by java.lang.Enum#ordinal
    // 从0开始计数
    @Enumerated(EnumType.ORDINAL)
    private GenderEnum gender3 = GenderEnum.FEMALE; // gender

    // alter table student add column gender4 integer
    private GenderEnum gender4 = GenderEnum.FEMALE; // gender

    // alter table student add column weekday varchar(10)
    @Type(type = "com.szr.leex.dao.converter.WeekType")
    @Column(length = 10)
    private WeekEnum weekday;

    // alter table student add column gender5 char(1)
    @Convert( converter = GenderConverter.class )
    private GenderEnum gender5 = GenderEnum.FEMALE; // gender

}
